package cn.iocoder.yudao.module.erp.dal.mysql.dpitem;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.erp.controller.admin.dpitem.dpitemwsl.vo.DpItemWslPageReqVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.dpitem.DpItemWslDO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;
import java.util.stream.Collectors;

/**
 * ERP乌苏里制单货号详情 Mapper
 * @author 天使管理员
 */
@Mapper
public interface DpItemWslMapper extends BaseMapperX<DpItemWslDO> {

    default PageResult<DpItemWslDO> selectPage(DpItemWslPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<DpItemWslDO>()
                .eqIfPresent(DpItemWslDO::getNo, reqVO.getNo())
                .eqIfPresent(DpItemWslDO::getType, reqVO.getType())
                .eqIfPresent(DpItemWslDO::getCount, reqVO.getCount())
                .eqIfPresent(DpItemWslDO::getLenth, reqVO.getLenth())
                .eqIfPresent(DpItemWslDO::getWide, reqVO.getWide())
                .eqIfPresent(DpItemWslDO::getHigh, reqVO.getHigh())
                .eqIfPresent(DpItemWslDO::getInVolume, reqVO.getInVolume())
                .eqIfPresent(DpItemWslDO::getWeight, reqVO.getWeight())
                .eqIfPresent(DpItemWslDO::getDensity, reqVO.getDensity())
                .eqIfPresent(DpItemWslDO::getIsSplit, reqVO.getIsSplit())
                .eqIfPresent(DpItemWslDO::getDispatchNumber, reqVO.getDispatchNumber())
                .eqIfPresent(DpItemWslDO::getInventoryStatus, reqVO.getInventoryStatus())
                .eqIfPresent(DpItemWslDO::getLineDetails, reqVO.getLineDetails())
                .betweenIfPresent(DpItemWslDO::getLineUpdateTime, reqVO.getLineUpdateTime())
                .orderByDesc(DpItemWslDO::getId));
    }

    default List<DpItemWslDO> selectListByNo(String no) {
        return selectList(DpItemWslDO::getNo, no);
    };

    default List<Long> selectListByNos(List<String> nos) {
        return selectObjs(new LambdaQueryWrapper<DpItemWslDO>()
                .in(DpItemWslDO::getNo, nos)
                .select(DpItemWslDO::getId)).stream()
                .map(obj -> (Long) obj) // 转换 Object 为 Long 类型
                .collect(Collectors.toList());
    };

    default int deleteByNo(String no) {
        return delete(DpItemWslDO::getNo, no);
    }

}